<?php
/**
 * [group ]
 * @author  zhuhui
 * @date    2019-07-19 14:49:53
 * @version [0.1]
 * @param $total [总人数]
 * @param $group_item_num [每个房间人数]
 * @param $which_people [要查询的第几个人的，如要查询第8个人在哪个房间$which_people=8]
 * @return string
 */
class Tool{
    public function group($total,$group_item_num,$which_people){
        $arr = [];
        for ($i = 1;$i <= $total;$i++){
            $arr[$i] = $i;
        }
        $groups = array_chunk($arr,$group_item_num);
        $return = '没有查询到数据';
        foreach ($groups as $k=>$group){
            if (in_array($which_people,$group)){
                $return = '第'.$which_people.'个人在'.($k+1).'房间';
                break;
            }
        }
        return $return;
    }

    public function group2($group_item_num,$which_people){
        $y = $which_people/$group_item_num;
        $m = $which_people%$group_item_num;
        if($m == 0){
            return $y;
        }else{
            // $y = $y+ 1;
            // return intval($y);
            return ceil($y);
        }
    }


    public function group3($group_item_num,$which_people){
        $y = $which_people/$group_item_num;
        $m = $which_people%$group_item_num;
        $arr = array();
        if($m == 0){
            $arr['id'] = $y; //房间号
            $arr['last']= true; //是否最后一个 例如能容纳6就是 第6个 第12个。。。
            $arr['di']= $group_item_num; //第6不是0是第6  第12不是0 是第6
            return $arr;
        }else{
            $y = ceil($y);
            $arr['id'] = $y;
            $arr['last']= false;
            $arr['di']= $m;
            return $arr;
        }
    }


    public function group4($group_item_num,$which_people){
        $n = ($which_people - 1 )/$group_item_num + 1 ;
        return intval($n);
    }

    public function open_message($fd,$house_arr){
       $data = "你连接fd是".$fd.",在".$house_arr['id']."房间,你是第".$house_arr['di']."个进这个房间的";
       return $data;
    }

    public function open_message_team($fd,$house_arr){
       $data = "你连接fd是".$fd.",在".$house_arr['id']."房间,你是第".$house_arr['di']."个进这个房间的";
       $team_arr = $this->group3(3,$house_arr['di']);  //6除以3 可以分两队（所以是两队打）
       $data .=' 小队编号:'.$team_arr['id'].'您是第'.$team_arr['di'].'号';
       return $data;
    }

    //找出你点的敌人fd
    public function find_fd($house_id,$team_id,$point){
        echo "此时房间号".$house_id;
        echo "小队号".$team_id;
        echo "点号".$point;
        $z = ($house_id-1)*6 + ($team_id -1)*3 +$point;
        return $z; 
    }

    //找出你点的敌人fd
    public function find_fd_more($fd,$point){
        $house_arr = $this->group3(6, $fd); 
        $house_di = $house_arr['di'];
        $team_arr =$this->group3(3,$house_di);  //6除以3 可以分两队（所以是两队打）
        $e_team_id = $team_arr['id']==1?2:1;    //
        $e_fd = $this->find_fd($house_arr['id'],$e_team_id,$point);
        return $e_fd;
    }




}